function creatApp(){
	var appName=$("#appName").val();
	var packageName=$("#packageName").val();
	var description=$("#description").val();
	var appType=$("#appType").find("option:selected").text()
	var appTypeNum=0;
	if(appType=="ios"){
		appTypeNum=1;
	}
	if(appName==""){
		layer.alert('APP名称不能为空', {
									icon: 5,
									skin: 'layer-ext-moon'
						});
	}
	else if(packageName==""){
		layer.alert('APP应用包名不能为空', {
									icon: 5,
									skin: 'layer-ext-moon'
						});
	}
	else if(appType==""){
		layer.alert('APP应用类型不能为空', {
									icon: 5,
									skin: 'layer-ext-moon'
						});
	}
	else{
		var postData={
			"appName":appName,
			"packageName":packageName,
			"appType":appTypeNum,
			"description":description,
			"userId":GetQueryString("id")
		}
		$.ajax({
			type:"POST",
			url:"/hotFixServer/application/createApp",
			data:postData,
			success: function(data){
				if(data.model['success']==0){
					layer.alert('创建成功', {
									icon: 6,
									skin: 'layer-ext-moon'
						});
					$("#appName").val("");
					$("#packageName").val("");
					$("#description").val("");
					$("#appType").val("android");
					$("#myAppModal").modal('hide');
					var appListHtmlAdd="<tr id="+data.model['applicationId']+">\r\n"+
							"<td>"+appName+"</td>\r\n"+
							"<td>"+appType+"</td>\r\n"+
							"<td>"+packageName+"</td>\r\n"+
							"<td>"+description+"</td>\r\n"+
							"<td><a href=\"manageversion.html?id="+data.model['applicationId']+"\" style=\"color:#CD8162\">管理</a>|<a  style=\"color:#242424\" href='javascript:void(0)' onclick=\"deleteApp('"+data.model['applicationId']+"')\">删除</a></td>\r\n"+
						"</tr>";
					$("#appTable").prepend(appListHtmlAdd);
				}
				else if(data.model['success']==1){
					layer.alert(data.model['info'], {
									icon: 5,
									skin: 'layer-ext-moon'
						});
				}
				else if(data.model['success']==-1){
					layer.alert(data.model['info'], {
									icon: 5,
									skin: 'layer-ext-moon'
						});
				}
				else if(data.model['success']==2){
					layer.alert(data.model['info'], {
									icon: 5,
									skin: 'layer-ext-moon'
						});
				}
				
			}
		});
	}
}

$(document).ready(function(){
	$.ajax({
            url:'/hotFixServer/application/applist?userId='+GetQueryString("id"),
            type:"GET",
			cache:false,
            success:function(data){
                for(var i=0;i<data.model['applist'].length;i++){
				var appType="android";
				if(data.model['applist'][i]['app_type']==1){
					appType="ios";
				}
				var appListHtml="<tr id="+data.model['applist'][i]['id']+">\r\n"+
								"<td>"+data.model['applist'][i]['app_name']+"</td>\r\n"+
								"<td>"+appType+"</td>\r\n"+
								"<td>"+data.model['applist'][i]['bundle_id']+"</td>\r\n"+
								"<td>"+data.model['applist'][i]['description']+"</td>\r\n"+
								"<td><a href=\"manageversion.html?id="+data.model['applist'][i]['id']+"\" style=\"color:#CD8162\">管理</a>|<a  style=\"color:#242424\" href='javascript:void(0)' onclick=\"deleteApp('"+data.model['applist'][i]['id']+"')\">删除</a></td>\r\n"+
							"</tr>";
				$("#appTable").append(appListHtml);
				}
			}
    });

});


function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}


//删除app
function deleteApp(id){
	var deleteData={
		"appId":id
		
	}
    layer.confirm('您确定删除吗？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $.ajax({
            url:'/hotFixServer/application/deleteApp',
            type:"DELETE",
            data:deleteData,
            success:function(data){
                if(data.model['success']==0){
                    layer.alert(data.model['info'], {
                        icon: 6,
                        skin: 'layer-ext-moon'
                    });
                    $('#'+id).remove();
                }
                else if(data.model['success']==1){
                    layer.alert(data.model['info'], {
                        icon: 5,
                        skin: 'layer-ext-moon'
                    });
                    location.reload(false);
                }
                else if(data.model['success']==-1){
                    layer.alert(data.model['info'], {
                        icon: 5,
                        skin: 'layer-ext-moon'
                    });
                    location.reload(false);
                }
            },
            error:function(xhr,textstatus,thrown){

            }
        });
    }, function(){
        layer.closeAll();
    });
}




